package com.blog4j.user.api;

import cn.dev33.satoken.annotation.SaIgnore;
import com.blog4j.common.annotation.OperationLog;
import com.blog4j.common.enums.ModuleTypeEnum;
import com.blog4j.common.model.Result;
import com.blog4j.requestRate.annotation.RequestRate;
import com.blog4j.user.service.OrganizationService;
import com.blog4j.user.vo.resp.OrganizationInfoRespVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 98k灬
 * @version v1.0.0
 * @Description : 功能描述
 * @Create on : 2024/8/9 20:47
 **/
@RestController
@RequestMapping("/api/organization")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class ApiOrganizationController {
    private final OrganizationService organizationService;

    /**
     * 根据组织ID获取组织信息
     *
     * @param organizationId 组织ID
     * @return 组织信息
     */
    @RequestRate
    @OperationLog(module= ModuleTypeEnum.USER, description = "根据组织ID获取组织信息")
    @SaIgnore
    @GetMapping("/organizationInfo")
    public Result organizationInfo(@RequestParam("organizationId") String organizationId) {
        OrganizationInfoRespVo resp = organizationService.organizationInfo(organizationId);
        return Result.ok(resp);
    }

    /**
     * 根据组织ID获取组织成员数
     *
     * @param organizationId 组织ID
     * @return 组织成员数
     */
    @RequestRate
    @OperationLog(module= ModuleTypeEnum.USER, description = "根据组织ID获取组织成员数")
    @SaIgnore
    @GetMapping("/organizationMembers")
    public Result organizationMembers(@RequestParam("organizationId") String organizationId) {
        Integer count = organizationService.organizationMembers(organizationId);
        return Result.ok(count);
    }

    /**
     * 获取组织列表
     *
     * @param keyword 关键字
     * @return 组织列表
     */
    @RequestRate
    @OperationLog(module= ModuleTypeEnum.USER, description = "获取组织列表")
    @GetMapping("/organizationList")
    public Result organizationList(@RequestParam(value = "keyword", required = false) String keyword) {
        List<OrganizationInfoRespVo> list = organizationService.organizationListByKeyword(keyword);
        return Result.ok(list);
    }
}
